package com.ayou.eggguard.farm.mapper;

import com.ayou.eggguard.farm.pojo.Announce;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AnnounceMapper {

    @Insert("insert into announce(username, title, content, create_time) " +
            "values (#{username},#{title},#{content},#{createTime})")
    void add(Announce announce);

    @Delete("delete from announce where id=#{id}")
    void delete(Integer id);

    @Update("update announce set title=#{title},content=#{content} " +
            "where id=#{id}")
    void updateAnnounce(Announce announce);

    List<Announce> getAnnounceByPage(String title);

    @Update("update announce set open=case " +
            "when open=0 then 1 " +
            "when open=1 then 0 " +
            "end where id=#{id}")
    void updateAnnounceStatus(Integer id);
}
